﻿/* 2012/10/5 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cosmos.Windows.Forms
{
    /// <summary>
    /// Provides static methods to manipulate controls.
    /// </summary>
    class ControlManager
    {
        internal static void AddControl(Control owner, Control control)
        {
            control.Dock = DockStyle.Fill;
            owner.SuspendLayout();

            owner.Controls.Add(control);
            owner.ResumeLayout();
        }

        internal static void RemoveControl(Control owner, Control control)
        {
            owner.SuspendLayout();
            owner.Controls.Remove(control);
            owner.SuspendLayout();
        }

        /// <summary>
        /// Move tab pages from a tab page collection to another.
        /// </summary>
        /// <param name="source">The tab page collection where tab pages are moved from.</param>
        /// <param name="target">The tab page collection where tab pages are moved to.</param>
        internal static void MoveTabPage(TabControl.TabPageCollection source, TabControl.TabPageCollection target)
        {
            while (source.Count != 0)
            {
                TabPage aTabPage = source[0];
                source.Remove(aTabPage);
                target.Add(aTabPage);
            }
        }

        /// <summary>
        /// Move tab pages from a tab page collection to another.
        /// </summary>
        /// <param name="source">The tab page collection where tab pages are moved from.</param>
        /// <param name="target">The tab page collection where tab pages are moved to.</param>
        /// <param name="indices">The indices of moved tab pages in source collection.</param>
        internal static void MoveTabPage(TabControl.TabPageCollection source, TabControl.TabPageCollection target, params TabPage[] pages)
        {
            foreach (TabPage aTabPage in pages)
            {
                if (source.Contains(aTabPage))
                {
                    source.Remove(aTabPage);
                    target.Add(aTabPage);
                }
            }
        }
    }
}
